/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.EditorMenu;

import General.CurrentData;
import other.Wizard;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.concurrent.Callable;
import javax.swing.*;

/**
 *
 * @author David
 */
public class EditMenu extends JMenu
{

    private JMenuItem duplicateItem = new JMenuItem("Duplicate");
    private JMenuItem deleteItem = new JMenuItem("Delete");
    private JMenuItem viewPortColorSelectionItem = new JMenuItem("ViewPort Color");
    private JMenuItem findItem = new JMenuItem("Find");

    /**
     *
     */
    public EditMenu()
    {
        initShortcuts();
        setEnabled(false);
        setText("Edit");
        add(duplicateItem);
        add(deleteItem);
        add(viewPortColorSelectionItem);
        add(findItem);
        initActions();
    }

    private void initActions()
    {
        viewPortColorSelectionItem.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                final Color vPortColor = new JColorChooser().showDialog(EditMenu.this, "ViewPort Color", Wizard.makeColor(CurrentData.getEditorWindow().getB3DApplication().getViewPort().getBackgroundColor()));
                CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Void>()
                {
                    public Void call() throws Exception
                    {
                        CurrentData.getEditorWindow().getB3DApplication().getViewPort().setBackgroundColor(Wizard.makeColorRGBA(vPortColor));
                        return null;
                    }
                });
            }
        });
    }

    private void initShortcuts()
    {
        deleteItem.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_DELETE, ActionEvent.CTRL_MASK));
        duplicateItem.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_D, ActionEvent.CTRL_MASK));
        findItem.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_F, ActionEvent.CTRL_MASK));
    }
}